package com.kun.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @descriptions: 自动填充
 * @author: SunKun
 * @date: 2021/7/5 0005 16:34
 * @version: 1.0
 */
@Component
public class MyMetaObjectHandler  implements MetaObjectHandler {

    // 插入时候的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("commentDate", new Date(), metaObject);
        this.setFieldValByName("clickHit", 0, metaObject);
        this.setFieldValByName("replyHit", 0, metaObject);
        this.setFieldValByName("releaseDate", new Date(), metaObject);
    }

    // 更新时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
//        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
